#!/bin/bash
# Author : Raman Rawat
# Usage
# ./BitteGerne.sh srcDir tgtDir r1 Rep1 [r2 Rep2 r3 Rep3 ]
# srcDir == Source directory to copy without ending /
# tgtDir == Target directory to copy without ending /
#sed -e 's/XXX/YYY/g' -e 's/MeshSeed/MIPF/g' DirsToCopy.txt

# CurrentWorkingDir
cwd=$PWD

echo "script name $0 "
echo `basename $0`
# find list of all files in dir 2 
cd $1
echo "In dir "$1

fileList=$cwd/FilesToCopy.txt
dirList=$cwd/DirsToCopy.txt
specialList=$cwd/SpecialFiles.txt

# make list of all files & dirs in $1
#FilesToCopy.txt format : FullPath(File/Dir)	ParentDir	FileName/DirName
find . -type f  -printf "\n%p %h \t %f" > $fileList
find . -type d -printf "\n%p %h \t %f" > $dirList

cd $cwd

sedArg=""

j=0
for ((i=${BASH_ARGC}-3 ; i > 0; i-=2))
do 
j=`expr i-1`
	echo "Replacing " ${BASH_ARGV[$i]} "with " ${BASH_ARGV[$j]}

	# replace the contents of the files

	#sedArg=$sedArg "-e \'s/${BASH_ARGV[$i]}/${BASH_ARGV[$j]}/g\'"
	sedArg="$sedArg -e 's/${BASH_ARGV[$i]}/${BASH_ARGV[$j]}/g' "
done

echo $sedArg

sedArg="sed $sedArg "$dirList
echo $sedArg

cat $dirList
eval $sedArg
#awk -v r="$sedArg" -f MultiRename.awk $1

    


